Skip to content

Support defining predicates using #[thrust::predicate] attribute with fn statements#23

Merged
coeff-aij merged 10 commits into
coord-e:mainfrom
coeff-aij:annot-preds-define
Jan 29, 2026
Merged

Support defining predicates using #[thrust::predicate] attribute with fn statements#23
coeff-aij merged 10 commits into
coord-e:mainfrom
coeff-aij:annot-preds-define

Conversation

@coeff-aij

@coeff-aij coeff-aij commented Jan 23, 2026

Copy link
Copy Markdown
Collaborator

This feature recognizes functions annotated with #[thrust::predicate] as predicates and inserts corresponding define-fun definitions—derived from their names and arguments—into the .smt2 file. The first string literal that appears in a function's body is inserted as the predicate body.

Compared with #![thrust::raw_command], Thrust can assign a predicate name automatically and later leverage that name to connect the predicate to relevant traits(for example, SomeTrait::pred -> (define-fun some_trait_pred)).

  • Example

If a user writes the following:

#[thrust::predicate]
fn is_double(x: i64, doubled_x: i64) -> bool {
    "(=
        (* x 2)
        doubled_x
    )"; true
}

the appropriate definitions are inserted into the .smt2 file.

(define-fun is_double ((x Int) (doubled_x Int)) Bool (=
        (* x 2)
        doubled_x
    ))

Comment thread src/chc.rs Outdated
pub struct UserDefinedPredDef {
symbol: UserDefinedPred,
sig: UserDefinedPredSig,
body: RawCommand,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's natural to use a String directly here, as RawCommand shouldn't serve a different purpose

Suggested change
body: RawCommand,
body: String,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed.

@coeff-aij

Copy link
Copy Markdown
Collaborator Author

I added more details to the PR description.

@coeff-aij coeff-aij requested a review from coord-e January 24, 2026 05:30
Comment thread src/chc/smtlib2.rs

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think raw‑command definitions and user‑defined predicates should be emitted before the datatype declarations in the generated .smt2 file.

The reason is that raw commands and predicates written by users may refer to previously declared datatypes(ex. access fieleds of structs), whereas datatype definitions emmitted by Thrust will not refer to those commands or predicates.

@coeff-aij coeff-aij merged commit 51084c6 into coord-e:main Jan 29, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants